<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>大攻略管理</title>
	<#include "../common/header.ftl" >

	<script src="/static/jquery/jquery-form/jquery.form.js" ></script>
	<script src="/static/jquery/jquery-bootstrap/jquery.bootstrap.min.js"></script>
	<script src="/static/My97DatePicker/WdatePicker.js"></script>

	<style>
		.modal-body img{
			width: 100%;
		}
	</style>


	<script>
		$(function () {
		    //添加触发模态框
			$('#addStrategyBtn').click(function () {
			    //清空回显内容
                $('#strategyModal input').val('');
                //设置更换图片的控件
                $('#strategyModal .btn-changePic').val('更换图片');
                $('#strategyModal #modal-coverUrl').remove();
                $('#strategyModal [name="coverUrl"]').before('<img width="200px" id="modal-coverUrl"/>');
                $('#strategyModal').modal('show');
            });

			//修改功能
            $('.btn-recomment').click(function () {
                var json = $(this).data('json');
                $('#strategyModal #id').val(json.id);
                $('#strategyModal [name="title"]').val(json.title);
                $('#strategyModal [name="subTitle"]').val(json.subTitle);
                $('#strategyModal [name="coverUrl"]').val(json.coverUrl);//传递图片的路径
                $('#strategyModal #modal-coverUrl').attr('src',json.coverUrl);
                $('#strategyModal [name="place.id"]').val(json.placeId);//传递图片的路径
                $('#strategyModal [name="state"]').val(json.state);//传递图片的路径
                $('#strategyModal .btn-changePic').val("更换图片");//传递图片的路径
                $('#strategyModal').modal('show');
            });

            //提交添加/修改表单
            $('#saveCommendBtn').click(function () {
                $('#commendForm').ajaxSubmit(function (data) {
                    if(data.success){
                        $.messager.alert('温馨提示','操作成功!  2s后刷新页面');
                        setTimeout(function () {
                            window.location.reload();
                        },2000);
                    }else{
                        $.messager.alert('温馨提示',data.msg);
                    }
                });
            });

            //更换封面按钮触发文件上传框事件
            $('.btn-changePic').click(function () {
                //触发文件上传框
                $('#fileForm [name=file]').click();
            });

            //当文件上传框的值改变就发请求更新
            $('#fileForm').change(function () {
                //判断是否有上传文件
                if($('#fileForm [name=file]').val()){
                    //提交表单
                    $('#fileForm').ajaxSubmit(function (data) {
                        //根据返回结果判断上传结果
                        if(data.status==1){
                            $('#strategyModal [name="coverUrl"]').val(data.url);
                            $('#strategyModal #modal-coverUrl').attr('src',data.url);
                        }else{
                            $(document).dialog({
                                content:data.msg
                            })
                        }
                    })
                }
            })
        })
	</script>
</head>
<body>

<div class="container " style="margin-top: 20px">
	<#include "../common/top.ftl" >
	<div class="row">
		<div class="col-sm-3">
            <!--设置用于菜单回显-->
                <#assign currentMenu="strategy">
			<#include "../common/menu.ftl" >
		</div>
		<div class="col-sm-9">
			<div class="row">
				<div class="col-sm-12">
					<h1 class="page-head-line">大攻略管理</h1>
				</div>
			</div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategy/list.do" method="post">
                <div class="form-group">
                    <input id="currentPage" type="hidden" name="currentPage" value="${(qo.currentPage)!}">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}" placeholder="请输入标题/地点">
                </div>


                <input type="submit" id="btn_query" class="btn btn-success" value="查询">

            </form>

            <button  class="btn btn-success" id="addStrategyBtn">添加攻略</button>

			<table class="table table-striped table-hover" >
				<thead>
				<tr>
                    <th >封面</th>
                    <th>攻略标题</th>
                    <th>副标题</th>
                    <th>所属地区</th>
                    <th>状态</th>

                </tr>
				</thead>
				<#list  pageInfo.list as strategy>
					<tr>
                        <td>
                            <img src='${(strategy.coverUrl)!}' width="100px">
                        </td>
                        <td>${(strategy.title)!}</td>
                        <td>${(strategy.subTitle)!}</td>
                        <td>${(strategy.place.name)!}</td>
                        <td>${(strategy.stateName)!}</td>
						<td>
							<button class="btn btn-info btn-xs btn-recomment"  data-json='${(strategy.jsonString)!}'>
								修改
							</button>

                        </td>
					</tr>
				</#list>
			</table>

			<#include "../common/page.ftl" >
		</div>
	</div>
</div>


<#--推荐模态框-->
<div id="strategyModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="commendForm" class="form-horizontal" method="post" action="/strategy/saveOrUpdate.do"  style="margin: -3px 118px">
                    <input id="id" type="hidden" name="id" value="" />
                    <div class="form-group">
                        <label class="col-sm-3 control-label">标题</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="title" placeholder="标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">副标题</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="subTitle" placeholder="副标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">封面</label>
                        <div class="col-sm-9">
                            <img width="200px" id="modal-coverUrl"/>
                            <input type="hidden" name="coverUrl"  >
                            <input TYPE="button" class="btn btn-info btn-xs btn-changePic" VALUE="更换图片" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">所属地区</label>
                        <div class="col-sm-9">
                            <select class="form-control" autocomplete="off" name="place.id" >
                                <#if regions??>
                                    <#list regions as region >
                                        <option value="${region.id}">${region.name}</option>
                                    </#list>
                                </#if>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">状态</label>
                        <div class="col-sm-9">
                            <select class="form-control" autocomplete="off" name="state" >
                                <option value="0">普通</option>
                                <option value="1">推荐</option>
                                <option value="-1">禁用</option>
                            </select>
                        </div>
                    </div>
                </form>
                <form id="fileForm" action="/images.do" method="post" enctype="multipart/form-data">
                    <input type="file" class="form-control"  name="file" style="display: none">
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveCommendBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>


</body>
</html>